package com.lmaos.basetools.files.scan;

public class ScanFile {
	
	private String rootPath; // 跟路径
	private String rootSuffix;
	private String filePath; // 文件路径
	private String className; // 如果是一个class 则可以直接得到className
	private String absolutePath;
	
	public ScanFile(String absolutePath) {
		this(ScanFileUtils.getFileString(absolutePath),ScanFileUtils.getFilePathString(absolutePath),ScanFileUtils.getFileAbsoluteString(absolutePath));
	}
	public ScanFile(String rootPath, String filePath,String absolutePath) {
		super();
		filePath = filePath.replace("\\", "/");
		this.rootPath = rootPath;
		this.filePath = filePath;
		this.absolutePath = absolutePath;
		int suffixIndex = rootPath.lastIndexOf(".");
		if(suffixIndex!=-1){
			this.rootSuffix = rootPath.substring(suffixIndex+1);
		}
		if(filePath.endsWith(".class")){
			className = filePath.replace("/", ".").substring(0, filePath.length()-".class".length());
		}
	}
	public String getRootPath() {
		return rootPath;
	}
	public String getRootSuffix() {
		return rootSuffix;
	}
	public String getFilePath() {
		return filePath;
	}
	public String getClassName() {
		return className;
	}
	public String getAbsolutePath() {
		return absolutePath;
	}
	@Override
	public String toString() {
		StringBuilder text = new StringBuilder();
		text.append("{");
		text.append("\"rootPath\":").append("\"").append(rootPath).append("\"");
		if(className!=null){
			text.append(",\"className\":").append("\"").append(className).append("\"");
		}else{
			text.append(",\"filePath\":").append("\"").append(filePath).append("\"");
		}
		text.append("}");
		return text.toString();
	}
}
